﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace KalevaAalto.DataPart.DataBasePart.Attributes
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)]
    public class DataTableAttribute : SqlSugar.SugarTable
    {
        public DataTableAttribute(string tableName) : base(tableName) 
        {
            TableName = tableName;
        }


        public static string GetTableName(Type type)
        {
            // 获取类的特性
            var attribute = type.GetCustomAttribute<DataTableAttribute>(true);

            // 如果类应用了特性，则输出特性的信息
            if (attribute is not null)
            {
                return attribute.TableName;
            }
            else
            {
                return type.Name;
            }
        }

        public static string GetTableName<T>()
        {
            Type type = typeof(T);
            return GetTableName(type);
        }


    }
}


